home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
131
/
applic
/
tinyustf.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-04-17
|
4KB
|
160 lines
PROGRAM TinyUnstuff; {Tiny to Neo format unstuffer. By Carlos Reyes}
CONST
Read_Only = 0;
TYPE
inbufType = PACKED ARRAY[1..32044] OF BYTE;
outbufType = PACKED ARRAY[1..32128] OF BYTE;
Path_Chars = PACKED ARRAY[1..80] OF CHAR;
VAR
f :Integer;
inbuf :inbufType;
outbuf :outbufType;
picname :String[80];
name :Path_Chars;
i :Integer;
FUNCTION f_create(VAR name :Path_Chars; attributes :Integer) :Integer;
GemDos($3c);
FUNCTION f_open(VAR name :Path_Chars; mode :Integer ) :Integer;
GemDos($3d);
FUNCTION f_close(handle :Integer) :Integer;
GemDos($3e);
FUNCTION f_read(handle :Integer; count :Long_Integer;
VAR buffer :inbufType) :Long_Integer;
GemDos($3f);
FUNCTION f_write( handle :Integer; count :Long_Integer;
VAR buffer :outbufType) :Long_Integer;
GemDos($40);
PROCEDURE Error;
BEGIN
Writeln;
Writeln('Error!!!');
Write('Press RETURN to exit: ');
Readln;
Halt;
END;
PROCEDURE DecodePic;
VAR
rotInfo :BOOLEAN;
res :INTEGER;
i, j :INTEGER;
curplane, curln, curcol :Integer;
ctrlptr, dataptr :Integer;
ctrlcnt, datacnt :Integer;
PROCEDURE PutWord;
VAR pos :Integer;
BEGIN
pos:=ShL(curplane,1)+curln*160+ShL(curcol,3);
outbuf[129+pos]:=inbuf[dataptr];
outbuf[129+pos+1]:=inbuf[dataptr+1];
curln:=curln+1;
IF curln>=200 THEN BEGIN
curln:=0;
curcol:=curcol+1;
IF curcol>=20 THEN BEGIN
curcol:=0;
curplane:=curplane+1;
Write('.');
END
END
END;
BEGIN
FOR i:=1 TO 128 DO outbuf[i]:=0;
res :=inbuf[1];
rotInfo:=True;
IF res>2 THEN res:=res-3 ELSE rotInfo:=False;
outbuf[4]:=res;
Write('Resolution: ');
IF res=0 THEN Writeln('Low')
ELSE IF res=1 THEN Writeln('Medium')
ELSE Writeln('High');
ctrlptr:=2;
IF rotInfo THEN ctrlptr:=ctrlptr+4;
FOR i:=1 TO 32 DO
outbuf[i+4]:=inbuf[ctrlptr+i-1];
ctrlptr:=ctrlptr+32;
ctrlcnt:=ShL(inbuf[ctrlptr],8)+inbuf[ctrlptr+1];
datacnt:=ShL(inbuf[ctrlptr+2],8)+inbuf[ctrlptr+3];
ctrlptr:=ctrlptr+4;
dataptr:=ctrlptr+ctrlcnt;
curplane:=0; curln:=0; curcol:=0;
REPEAT
IF inbuf[ctrlptr]>=128 THEN BEGIN
FOR j:=1 TO (256-inbuf[ctrlptr]) DO BEGIN
PutWord;
dataptr:=dataptr+2;
END;
ctrlptr:=ctrlptr+1;
END
else IF inbuf[ctrlptr]=0 THEN BEGIN
FOR j:=1 TO (inbuf[ctrlptr+1]*256+inbuf[ctrlptr+2]) DO
PutWord;
ctrlptr:=ctrlptr+3;
dataptr:=dataptr+2;
END
else IF inbuf[ctrlptr]=1 THEN BEGIN
FOR j:=1 TO (inbuf[ctrlptr+1]*256+inbuf[ctrlptr+2]) DO BEGIN
PutWord;
dataptr:=dataptr+2;
END;
ctrlptr:=ctrlptr+3;
END
else BEGIN
FOR j:=1 TO inbuf[ctrlptr] DO {inbuf[ctrlptr]>1}
PutWord;
ctrlptr:=ctrlptr+1;
dataptr:=dataptr+2;
END;
UNTIL (curplane>=4);
Writeln;
END;
BEGIN
Writeln('Tiny to Neo format converter.');
Writeln;
Write('Name of Tiny picture: ');
Readln(picname);
FOR i:=1 to Length(picname) DO name[i]:=picname[i];
name[ Length(picname)+1 ]:=Chr(0);
f:=f_open(name, Read_Only);
IF f < 0 THEN Error;
Write('Reading picture...');
IF f_read(f, 32044, inbuf) < 42 THEN Error;
IF f_close(f) < 0 THEN Error;
Writeln;
Writeln('Decoding picture...');
DecodePic;
Delete(picname, Length(picname)-3, 4);
picname := Concat(picname, '.neo');
FOR i:=1 to Length(picname) DO name[i]:=picname[i];
name[ Length(picname)+1 ]:=Chr(0);
f:=f_create(name, 0);
IF f < 0 THEN Error;
Write('Writing picture...');
IF f_write(f, 32128, outbuf) <> 32128 THEN Error;
IF f_close(f) < 0 THEN Error;
Writeln;
END.